package com.study.casedemo;

import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        // 案例1：买飞机票
        // 需求：机票按淡季旺季，头等舱或经济舱收费，输入机票原价、月份、淡季或旺季。
        // 按照如下价格计算机票：旺季（5~10月）头等舱9折，经济舱8.5折；淡季（11月到来年4月）头等舱7折，经济舱6.5折

        Scanner sc = new Scanner(System.in);
        System.out.println("输入机票原价：");
        double money = sc.nextDouble();
        System.out.println("请输入月份：");
        int month = sc.nextInt();
        System.out.println("请输入购买舱位（头等舱|经济舱）：");
        String type = sc.next();
        double calc = calc(money, month, type);
        System.out.println("你折扣后的机票价格为："+calc);
    }

    public static double calc(double money,int month,String type){
        if (money >0){
            if (month > 4 && month <11){
               money = discount(money,type,0.9,0.85);
            }else if (month == 11 || month == 12 || month >= 1 && month <= 4){
               money = discount(money,type,0.7,0.65);
            }else {
                System.out.println("你输入的月份有误！");
                money = -1;
            }
        }else {
            System.out.println("你输入的机票价格有误!");
            money = -1;
        }
        return money;
    }

    public static double discount(double money,String type,double disc1,double disc2){
        switch (type) {
            case "头等舱":
                money *= disc1;
                break;
            case "经济舱":
                money *= disc2;
                break;
            default:
                System.out.println("你输入的舱位有误！");
                money = -1;
        }
        return money;
    }
}
